package com.xw.mykotlin

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import com.xw.kotlinlib.base.BaseActivity
import com.xw.mykotlin.R
import com.xw.mykotlin.databinding.ActivityMain2Binding
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

class MainActivity2 : BaseActivity() {

    private val binding by lazy { ActivityMain2Binding.inflate(layoutInflater) }
    private val viewModel by lazy { ViewModelProvider(this)[Main2ViewModel::class.java] }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        viewModel.getCategory("23008",1)
            .onEach {
                Log.d("info","==flow请求长度===" + it.size)
            }
            .catch {
                it.printStackTrace()
            }
            .launchIn(lifecycleScope)
    }
}